package jfuzzyprincepless.negotiation.impl;

import jfuzzyprincepless.negotiation.DefaultNegotiationContext;
import jfuzzyprincepless.negotiation.INegotiationContext;
import jfuzzyprincepless.negotiation.services.IService;

/**
 * decorator: all modifications of decorator would be stored here
 * original context would not be changed
 */
public class OverrideInCopyContext
	extends DefaultNegotiationContext
	/**
	 * XXX: here aggregation is better then extension
	 * -- create field DefaultNegotiationContext copyContext
	 * and use it in such a way:
	 * super.getService(clazz) -> copyContext.getService(clazz)
	 */
{
	private INegotiationContext originalContext;

	public OverrideInCopyContext(
		INegotiationContext originalContext
	) {
		this.originalContext = originalContext;
	}

	@Override
	public <ServT extends IService> ServT getService(Class<ServT> clazz) {
		ServT result = super.getService(clazz);
		if (result != null) {
			return result;
		} else {
			return originalContext.getService(clazz);
		}
	}
}
